<template>
	<view>
		<!-- 地址 -->
		<view class="address" v-if="address!=null" @click="toadd">
			<view class="iconadd">
				<image style="width: 25rpx;" src="../../static/pay/address.png" mode="widthFix"></image>
			</view>
			<view class="info">
				<view>
					<text>{{address.name}}</text>
					<text style="margin-left: 40rpx;">{{address.phone}}</text>
				</view>
				<view class="add_detail">{{address.provinceName}}{{address.cityName}}{{address.regionName}}{{address.detail}}</view>
			</view>
			<view>
				<image style="width: 18rpx;" src="../../static/pay/icon_right.png" mode="widthFix"></image>
			</view>
		</view>
		<view class="xzadd" @click="toadd" v-else>
			点击选择地址
		</view>
		
		<!-- 商品信息 -->
		<view class="product_box">
			<view>
				<image style="width: 161rpx; height: 161rpx;" :src="dataInfo.imageUrl" mode="aspectFill"></image>
			</view>
			<view class="product_details">
				<view class="product_name">{{dataInfo.goodsName}}</view>
				<view class="product_specs">{{dataInfo.specSkuName}}</view>
				<view class="product_price" >{{bargainTask.goodsPrice - bargainTask.cutMoney}}积分</view>
			</view>
		</view>
		<!-- 规格 -->
		<view class="guige_box" >
			<view class="guige">
				<view class="text">支付方式</view>
				<view class="number">积分支付</view>
			</view>
			<!-- <view class="guige">
				<view class="text">赠送积分</view>
				<view class="number">{{dataInfo.givePoint}}</view>
			</view> -->
			<view class="guige">
				<view class="text">运费</view>
				<view class="number">￥0.00</view>
			</view>
			<view class="guige liu">
				<view class="text">备注:</view>
				 <input type="text" v-model="liuyan" placeholder="请填写备注信息" class="input"/>
			</view>
		</view>
		<!-- 底部 -->
		<view class="bottom">
			<view class="payment_bottom">
				<text class="shifu">实付</text>
				<text class="shifu shifu_price" >{{bargainTask.goodsPrice - bargainTask.cutMoney}}积分</text>
			</view>
			<view class="submit" @click="ok">提交订单</view>
		</view>
	</view>
</template>

<script>
	let url="/activity/buyBargainGoods"
	import {buyKj}from"../../api/product.js"
	export default{
		data() {
			return {
				address:null,
				dataInfo:{},
				dataList:[],
				num:0,
				liuyan:"",
				type:0,
				price:0,
				ids:"",
				activeId:null,
				bargainTask:""
			}
		},
		onLoad(e) {
			this.getInfo(e.id)
			this.activeId=e.id
		},
		onShow() {
			uni.$once('setAddress',(data)=>{
			    console.log(data);
				this.address=data
				uni.$off('setAddress')
			})
		},
		methods: {
			//获取正常购买商品订单信息
			async getInfo(id){
				let res=await this.iget(url,{taskId:id})
				// console.log(res)
				if(res.code==1){
					this.address=res.data.userDefaultAddress
					this.dataInfo=res.data.goodsInfo
					this.bargainTask=res.data.bargainTask
				}else if(res.code==0){
					this.msg(res.msg,"none")
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},1500)
				}
			},
			// 去更换地址
			toadd(){
				uni.navigateTo({
					url:"/pages/address/addresslist?type=xz"
				})
			},
			// 下单
			async ok(){
				if(this.address==null){
					this.msg("收货地址未选择","none")
				}else{
					let res=await this.post(buyKj,{orderAddressId:this.address.addressId,taskId:this.activeId})
					this.msg("下单成功")
					let price=this.bargainTask.goodsPrice - this.bargainTask.cutMoney
					setTimeout(()=>{
						uni.navigateTo({
							url:"/pages/product/paysuccess?type=2&price="+price+"&code="+res.data
						})
					},1500)
				}
			}
		}
	}
</script>

<style scoped="">
	.input{
		font-size: 26rpx;
		width: 500rpx;
	}
	.liu{
		justify-content: flex-start !important;
	}
	.xzadd{
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		font-weight: bold;
		font-size: 32rpx;
		color:#F0812D ;
	}
	.address{
		width: 690rpx;
		margin: 26rpx auto;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.info{
		width: 600rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #000000;
	}
	.iconadd{
		position: relative;
		top: -20rpx;
	}
	.add_detail{
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
		margin-top: 12rpx;
	}
	.product_box{
		width: 690rpx;
		height: 161rpx;
		margin: 60rpx auto 0;
		display: flex;
		/* align-items: center; */
	}
	.product_details{
		margin-left: 30rpx;
	}
	.product_name{
		font-size: 26rpx;
		font-weight: 800;
		color: #333333;
		overflow: hidden;  
		text-overflow: ellipsis;  
		display: -webkit-box;  
		-webkit-line-clamp: 2;  
		-webkit-box-orient: vertical; 
	}
	.product_specs{
		font-size: 22rpx;
		font-weight: 400;
		color: #666666;
		margin-top: 14rpx;
	}
	.product_price{
		font-size: 32rpx;
		font-weight: bold;
		color: #F0812D;
		margin-top: 10rpx;
	}
	.guige_box{
		width: 690rpx;
		margin: 130rpx auto 0;
	}
	.guige{
		width: 690rpx;
		margin: 45rpx auto;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.text{
		font-size: 26rpx;
		font-weight: 600;
		color: #666666;
	}
	.number{
		font-size: 28rpx;
		font-weight: 800;
		color: #000000;
	}
	.bottom{
		width: 750rpx;
		height: 88rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		background: #F6F6F6;
		line-height: 88rpx;
		display: flex;
	}
	.payment_bottom{
		width: 507rpx;
		padding-left: 30rpx;
	}
	.shifu{
		font-size: 28rpx;
		font-weight: bold;
		color: #000000;
	}
	.shifu_price{
		margin-left: 10rpx;
	}
	.submit{
		width: 243rpx;
		height: 88rpx;
		background: linear-gradient(90deg, #F3C44E 0%, #F18D29 53%, #ED6138 100%);
		z-index: 3;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 88rpx;
		color: #FFFFFF;
		text-align: center;
	}
</style>
